package cn.itcast.servlet;

import cn.itcast.domain.Student;
import cn.itcast.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/FindAllStudentServlet")
public class FindAllStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");

            //1.获取表单数据

            //2.调用service
            List<Student> students = new StudentServiceImpl().findAll();

            //3.页面跳转
            request.setAttribute("STUDENTS",students);
            request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response);
        }catch (Exception e){
            response.getWriter().println("服务器停电了");
        }

    }
}
